package com.example.airobotinterviewrecord.handler;

import com.example.airobotinterviewrecord.entity.enums.InterviewStatus;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class InterviewStatusTypeHandler extends BaseTypeHandler<InterviewStatus> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, InterviewStatus parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i, parameter.getCode());  // 存入数据库的值
    }

    @Override
    public InterviewStatus getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return InterviewStatus.fromCode(rs.getInt(columnName));  // 从数据库读取转换
    }

    @Override
    public InterviewStatus getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return InterviewStatus.fromCode(rs.getInt(columnIndex));
    }

    @Override
    public InterviewStatus getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return InterviewStatus.fromCode(cs.getInt(columnIndex));
    }
}
